package com.caac.core.web.action.setting;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.caac.core.dm.User;
import com.caac.core.service.ViewPropManager;
import com.caac.core.util.HttpUtils;
import com.caac.core.web.action.BaseAction;
import com.caac.core.web.form.BaseForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

/**
 * <p>Title: </p>
 * <p>Description: </p>
 * <p>Copyright: Copyright Intolong 2004</p>
 * <p>Company: Intolong</p>
 * @author <a href="mailto:intolong@163.com">Intolong</a>
 * @version 1.0
 */

public class SaveViewPropAction extends BaseAction {
    private static final String KEY_GROUP_NAME = "groupName";
    private static final String KEY_SEL_PROPS = "selProps";
    private static final String KEY_UNSEL_PROPS = "unselProps";

    protected ActionForward doExecute(ActionMapping mapping, BaseForm form,
                                      HttpServletRequest request,
                                      HttpServletResponse response) throws
            Exception {
        User user = this.getUserFromCache(request, response);
        String username = null;
        if (user != null) {
            username = user.getUsername();
        }
        String groupName = HttpUtils.getParameter(request, KEY_GROUP_NAME);
        ViewPropManager vpm = getViewPropManager();
        List selProps = vpm.getSelectedViewPropsByGroupName(groupName, username);
        List unselProps = vpm.getUnselectedViewPropsByGroupName(groupName,
                username);
        HttpUtils.setAttribute(request, KEY_SEL_PROPS, selProps);
        HttpUtils.setAttribute(request, KEY_UNSEL_PROPS, unselProps);
        return forward(mapping);
    }
}
